package com.weicx.wuzhiops.controller;


import com.weicx.wuzhiops.annotation.EventLog;
import com.weicx.wuzhiops.annotation.RestWrapper;
import com.weicx.wuzhiops.constant.event.EventType;
import com.weicx.wuzhiops.model.request.RepairRecordRequest;
import com.weicx.wuzhiops.model.wrapper.DataGrid;
import com.weicx.wuzhiops.service.RepairRecordService;
import com.weicx.wuzhiops.util.ServletsUtil;
import com.weicx.wuzhiops.util.Valid;
import com.weicx.wuzhiops.vo.RepairRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备报修记录表 前端控制器
 * </p>
 *
 * @author caoshi
 * @since 2022-12-13
 */
@Api(value = "设备报修记录", tags = {"设备报修记录"})
@RestController
@RestWrapper
@RequestMapping(ServletsUtil.BASE_REQUEST_PATH_PREFIX + "/repair/record")
public class RepairRecordController {


    @Resource
    private RepairRecordService repairRecordService;


    @PostMapping("/add")
    @ApiOperation(value = "新增报修记录")
    @EventLog(value = EventType.ADD_REPAIR_RECORD)
    public Long addRepairRecord(@RequestBody RepairRecordRequest request) {
        return repairRecordService.addRepairRecord(request);
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除报修记录")
    @EventLog(value = EventType.DELETE_REPAIR_RECORD)
    public Integer delete(@RequestBody RepairRecordRequest request) {
        List<Long> idList = request.getIdList();
        Valid.notEmpty(idList);
        return repairRecordService.deleteRepairRecord(idList);
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改报修记录")
    @EventLog(value = EventType.UPDATE_REPAIR_RECORD)
    public Integer update(@RequestBody RepairRecordRequest request) {
        Long id = request.getId();
        Valid.notNull(id);
        return repairRecordService.updateRepairRecord(request);
    }


    @PostMapping("/list")
    @ApiOperation(value = "获取报修记录列表")
    public DataGrid<RepairRecordVO> list(@RequestBody RepairRecordRequest request) {
        return repairRecordService.listRepairRecord(request);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id获取报修记录")
    public RepairRecordVO getRepairRecord(@RequestBody RepairRecordRequest request) {
        Long id = Valid.notNull(request.getId());
        return repairRecordService.getRepairRecord(id);
    }

}

